package com.jn.gsondemo.views;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.jn.gsondemo.R;
import com.jn.gsondemo.base.BaseActivity;
import com.jn.gsondemo.entity.Book;
import com.jn.gsondemo.utils.FileUtils;

public class BookActivity extends BaseActivity {

    @Override
    public int getLayoutId() {
        return R.layout.activity_book;
    }

    @Override
    public void init() {
        findViewById(R.id.iv_left_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        String fromAssets = FileUtils.getFromAssets(this, "book.json");
        System.out.println(fromAssets);
        Gson gson = new Gson();
        Book book = gson.fromJson(fromAssets, Book.class);
        System.out.println("===========" + book.reason);
        TextView title = findViewById(R.id.title);
        ImageView img = findViewById(R.id.img);
        Glide.with(this).load(book.result.data.img).into(img);
        StringBuilder sb = new StringBuilder();
        sb.append("标题：").append(book.result.data.title).append("\n");
        sb.append("种类：").append(book.result.data.catalog).append("\n");
        sb.append("标签：").append(book.result.data.tags).append("\n");
        sb.append("说明：").append(book.result.data.sub1).append("\n");
        sb.append("说明：").append(book.result.data.sub2).append("\n");
        sb.append("阅读人数：").append(book.result.data.reading).append("\n");
        sb.append("在线链接：").append(book.result.data.online).append("\n");
        sb.append("购买时间：").append(book.result.data.bytime).append("\n");
        title.setText(sb.toString());
    }
}